package com.mstore.service;

import java.util.ArrayList;
import java.util.List;

import com.mstore.dao.NoticeDao;
import com.mstore.pojo.Notice;

public class NoticeService {

	private NoticeDao noticeDao;
	
	/**
	 * 保存新的通知
	 */
	public void addNotices(Notice notice) {
		noticeDao.addNotices(notice);
	}

	/**
	 * 查询企业通知
	 */
	public List<Notice> getNoticesByEaid(Long eaId) {
		List<Notice> notices = new ArrayList<Notice>();
		List<Object> objcets = noticeDao.getNoticesByEaid(eaId);
		for (Object object : objcets) {
			notices.add((Notice) object);
		}
		return notices;
	}
	
	/**
	 * 根据类型查询企业通知条数
	 */
	public List<Notice> getCountNoticesByType(Long eaId) {
		List<Notice> notices = new ArrayList<Notice>();
		List<Object> objects = noticeDao.getCountNoticesByType(eaId);
		for (Object object : objects) {
			Object[] objs = (Object[])object;
			Notice notice = new Notice();
			notice.setType((Integer)objs[0]);
			notice.setCount((Long)objs[1]);
			notices.add(notice);
		}
		return notices;
	}
	
	/**
	 * 修改通知的状态
	 */
	public void modifyReadStatus(Long eaId, Integer type) {
		noticeDao.modifyReadStatus(eaId, type);
	}

	public NoticeDao getNoticeDao() {
		return noticeDao;
	}

	public void setNoticeDao(NoticeDao noticeDao) {
		this.noticeDao = noticeDao;
	}

}
